from django.contrib.auth.models import AbstractUser
from django.db import models


# Create your models here.
class UserInfo(AbstractUser):
    gender_choices = (
        ('M', '男'),
        ('F', '女')
    )

    class Meta:
        db_table = "user_info"

    phone = models.CharField(max_length=11, default=None, null=True)
    gender = models.CharField(max_length=5, choices=gender_choices, default=None, null=True)
    occupation = models.CharField(max_length=20, default=None, null=True)
    Remarks = models.TextField(max_length=20, default=None, null=True)
    avatar = models.ImageField(upload_to='media/images/', default=None, null=True)


class Loginlogs(models.Model):
    class Meta:
        db_table = "loginlog"
        verbose_name = "登录日志"

    username = models.CharField(max_length=50, default=None)
    ip = models.CharField(max_length=50, default=None)
    login_time = models.DateTimeField(default=None)


class TouTiao(models.Model):
    class Meta:
        db_table = "toutiao"
        verbose_name = "头条"

    name = models.CharField(max_length=200, default=None, unique=True)
    url = models.CharField(max_length=200, default=None)
    create_time = models.DateTimeField(auto_now_add=True)


class Witticism(models.Model):
    class Meta:
        db_table = "witticism"
        verbose_name = "每日一言"

    author = models.CharField(max_length=50, default=None)
    content = models.CharField(max_length=500, default=None, unique=True)
    from_by = models.CharField(max_length=50, default=None)
    pic_url = models.CharField(max_length=200, default=None)
    thumb = models.CharField(max_length=200, default=None)
    create_time = models.DateTimeField(auto_now_add=True)


class PageView(models.Model):
    url = models.CharField(max_length=255, unique=True)
    count = models.PositiveIntegerField(default=0)

    def __str__(self):
        return f"{self.url}: {self.count}"
